home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / think / AmigaGnuChess.lha / chess / src.lha / src / ataks.h < prev    next >
C/C++ Source or Header  |  1992-08-28  |  4KB  |  173 lines

  1. /*
  2.  * ataks.h - Header source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. #ifdef AMIGA    /* no inline... */
  24.  
  25. #ifndef ATAKS
  26. extern int SqAtakd (register short int sq, short int side);
  27. #else
  28.  
  29. int
  30. SqAtakd (register short int sq, short int side)
  31.  
  32. /*
  33.  * See if any piece with color 'side' ataks sq.  First check pawns then
  34.  * Queen, Bishop, Rook and King and last Knight.
  35.  */
  36.  
  37. {
  38.   register short u;
  39.   register unsigned char *ppos, *pdir;
  40.   short xside;
  41.  
  42.   xside = side ^ 1;
  43.   pdir = nextdir[ptype[xside][pawn]][sq];
  44.   u = pdir[sq];            /* follow captures thread */
  45.   if (u != sq)
  46.     {
  47.       if (board[u] == pawn && color[u] == side)
  48.     return (true);
  49.       u = pdir[u];
  50.       if (u != sq && board[u] == pawn && color[u] == side)
  51.     return (true);
  52.     }
  53.   /* king capture */
  54.   if (distance (sq, PieceList[side][0]) == 1)
  55.     return (true);
  56.   /* try a queen bishop capture */
  57.   ppos = nextpos[bishop][sq];
  58.   pdir = nextdir[bishop][sq];
  59.   u = ppos[sq];
  60.   do
  61.     {
  62.       if (color[u] == neutral)
  63.     u = ppos[u];
  64.       else
  65.     {
  66.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  67.         return (true);
  68.       u = pdir[u];
  69.     }
  70.   } while (u != sq);
  71.   /* try a queen rook capture */
  72.   ppos = nextpos[rook][sq];
  73.   pdir = nextdir[rook][sq];
  74.   u = ppos[sq];
  75.   do
  76.     {
  77.       if (color[u] == neutral)
  78.     u = ppos[u];
  79.       else
  80.     {
  81.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  82.         return (true);
  83.       u = pdir[u];
  84.     }
  85.   } while (u != sq);
  86.   /* try a knight capture */
  87.   pdir = nextdir[knight][sq];
  88.   u = pdir[sq];
  89.   do
  90.     {
  91.       if (color[u] == side && board[u] == knight)
  92.     return (true);
  93.       u = pdir[u];
  94.   } while (u != sq);
  95.   return (false);
  96. }
  97.  
  98. #endif /* ATAKS */
  99. #else /* AMIGA */
  100.  
  101.  
  102. inline
  103. static
  104. int
  105. SqAtakd (register short int sq, short int side)
  106.  
  107. /*
  108.  * See if any piece with color 'side' ataks sq.  First check pawns then
  109.  * Queen, Bishop, Rook and King and last Knight.
  110.  */
  111.  
  112. {
  113.   register short u;
  114.   register unsigned char *ppos, *pdir;
  115.   short xside;
  116.  
  117.   xside = side ^ 1;
  118.   pdir = nextdir[ptype[xside][pawn]][sq];
  119.   u = pdir[sq];            /* follow captures thread */
  120.   if (u != sq)
  121.     {
  122.       if (board[u] == pawn && color[u] == side)
  123.     return (true);
  124.       u = pdir[u];
  125.       if (u != sq && board[u] == pawn && color[u] == side)
  126.     return (true);
  127.     }
  128.   /* king capture */
  129.   if (distance (sq, PieceList[side][0]) == 1)
  130.     return (true);
  131.   /* try a queen bishop capture */
  132.   ppos = nextpos[bishop][sq];
  133.   pdir = nextdir[bishop][sq];
  134.   u = ppos[sq];
  135.   do
  136.     {
  137.       if (color[u] == neutral)
  138.     u = ppos[u];
  139.       else
  140.     {
  141.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  142.         return (true);
  143.       u = pdir[u];
  144.     }
  145.   } while (u != sq);
  146.   /* try a queen rook capture */
  147.   ppos = nextpos[rook][sq];
  148.   pdir = nextdir[rook][sq];
  149.   u = ppos[sq];
  150.   do
  151.     {
  152.       if (color[u] == neutral)
  153.     u = ppos[u];
  154.       else
  155.     {
  156.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  157.         return (true);
  158.       u = pdir[u];
  159.     }
  160.   } while (u != sq);
  161.   /* try a knight capture */
  162.   pdir = nextdir[knight][sq];
  163.   u = pdir[sq];
  164.   do
  165.     {
  166.       if (color[u] == side && board[u] == knight)
  167.     return (true);
  168.       u = pdir[u];
  169.   } while (u != sq);
  170.   return (false);
  171. }
  172.  
  173. #endif /* AMIGA */